/**
 * @author:albert
 */

package com.bkbw.live.battle.business.ai;

import com.badlogic.gdx.ai.msg.Telegram;

import com.bkbw.live.battle.business.UnitObject;

// actually speaking, this is BehaviorTree Node, but we use behavior pattern in game development
// so to distinguish BehaviorTree & Behavior Pattern we use Goal as BehaviorTree Node
public class Goal<EntityType extends UnitObject> {
	public enum Status {
		Active, Inactive, Completed, Failed;
	}
	
	protected Status status;
	protected EntityType owner;
	
	public Goal(EntityType entity) {
		
	}
	
	// ----------- to be override -----------
	public void activate() {
		
	}
	
	public Status process() {
		return null;
	}
	
	public void terminate() {
		
	}
	
	public boolean handleMessage(Telegram msg) {
		return false;
	}
	
	// ----------------------
	
	public void addSubgoal(Goal<EntityType> goal) {
		throw new RuntimeException("can't add subgoal to goal");
	}
	
	public boolean isComplete() {
		return status == Status.Completed;
	}
	
	public boolean isActive() {
		return status == Status.Active;
	}
	
	public boolean isInactive() {
		return status == Status.Inactive;
	}
	
	public boolean isFailed() {
		return status == Status.Failed;
	}
	
	protected void activateIfInactive() {
		if (isInactive()) {
			activate();
		}
	}
	
	protected void reactivateIfFailed() {
		if (isFailed()) {
			status = Status.Inactive;
		}
	}
}
